import React, { useState, useEffect } from 'react'
import { Card, Table, type TableProps, Tag } from 'antd'
import styles from '@/views/overview/index.module.scss'
// import styles from "../index.module.scss"
interface propsData {
  list: any
  moreFun?: () => void
}

interface DataType {
  key: string
  params1: string
  params2: string
  params3: number
  params4: string
}

const tableColumns: TableProps<DataType>['columns'] = [
  {
    title: '',
    dataIndex: 'params1',
    key: 'params1',
    ellipsis: true,
  },
  {
    title: '',
    dataIndex: 'params2',
    key: 'params2',
    ellipsis: true,
  },
  {
    title: '',
    dataIndex: 'params3',
    key: 'params3',
    render: (_, record) => {
      if (record.params3 === 0) {
        return <Tag color="green">待处理</Tag>
      } else if (record.params3 === 1) {
        return <Tag color="red">处理中</Tag>
      } else if (record.params3 === 2) {
        return <Tag color="orange">已处理</Tag>
      } else {
        return <span>{record.params3}</span>
      }
    },
  },
  {
    title: '',
    dataIndex: 'params4',
    key: 'params4',
    ellipsis: true,
  },
]

const DataBox: React.FC<propsData> = ({ list }) => {
  const [dataSource, setDataSource] = useState<DataType[]>([])
  useEffect(() => {
    const listData: DataType[] = list.map((item: any) => {
      return {
        key: item.key,
        params1: item.params1,
        params2: item.params2,
        params3: item.params3,
        params4: item.params4,
      }
    })
    setDataSource(listData)
    console.log(listData)
  }, [list])
  return (
    <Card
      className={styles['box2']}
      title="通知公告"
      extra={
        <a
          href={'http://139.196.21.184/#/iframeView?n=http%253A%252F%252F139.196.21.184%253A8989%252F%2523%252Fnotify'}
          target="_blank"
          className={styles['more']}
        >
          更多〉
        </a>
      }
    >
      <Table dataSource={dataSource} pagination={false} columns={tableColumns} showHeader={false} size="middle"></Table>
    </Card>
  )
}
export default DataBox
